package com.shop.feignClient.fallbackFactory;

import com.shop.po.R;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.shop.feignClient.AliyunClient;

/**
 * @author 'banxia'
 * @version 1.0
 * @description TODO
 * @date 2023/2/23 15:51
 */
@Slf4j
@Component//依赖模块也能被加入到容器管理么？
public class AliyunFallback implements FallbackFactory<AliyunClient> {
    @Override
    public AliyunClient create(Throwable throwable) {
        return new AliyunClient() {
            @Override
            public R uploadOssFile(MultipartFile file, String path) {
                log.error("调用阿里云上传文件发送熔断,异常信息:{}",throwable.getMessage());
                return R.error("文件上传超出熔断时间，建议上传较小文件");
            }

            @Override
            public R sendMessage(String redisKey, String phone) {
                log.error("调用阿里云发送短信发送熔断,异常信息:{}",throwable.getMessage());
                return R.error("发送短信失败！请重新发送");
            }
        };
    }
}
